package com.duing.util;



import nl.siegmann.epublib.domain.*;
import nl.siegmann.epublib.epub.EpubReader;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class EpubUtil {
    public static void main(String[] args) {
        File file = new File("epub/pg.epub");

        InputStream in = null;

        try {
            in = new FileInputStream(file);

            EpubReader epubReader = new EpubReader();

            Book book = epubReader.readEpub(in);
            System.out.println("title :" +   book.getTitle());

            Resources resources = book.getResources();
            System.out.println( "size :" + resources.size());

            Spine  spine = book.getSpine();
            System.out.println("spine size :" + spine.size());

            List<SpineReference> spineReferences = spine.getSpineReferences();
            for (SpineReference spineReference : spineReferences) {
                Resource resource = spineReference.getResource();
                System.out.println("resource :" + resource.getHref());
            }
        }catch (Exception e){
            System.out.println("error" + e.getMessage());
        }finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    System.out.println("error" + e.getMessage());
                }
            }
        }

    }
}
